{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "RunMeshroom.ipynb",
      "provenance": [],
      "collapsed_sections": [],
      "toc_visible": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "tJUlZN4TRnCH",
        "colab_type": "text"
      },
      "source": [
        "This notebook is based off of [donmahallem's](https://github.com/donmahallem) MeshroomColab [notebook](https://gist.github.com/donmahallem/22134574382b7bd8a67c1550734fcfc4).\n",
        "\n",
        "If you need help, check out [my YouTube](https://bit.ly/ab3dchannel) and [my GitHub](https://github.com/ab3d-studio)."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "RD3eZSm6d6NZ",
        "colab_type": "text"
      },
      "source": [
        "#Setup\n",
        "Add paths for input and output. Your images should be in their own folder. Or just check use sample data, and the input and ouput will be covered for you. For ease of use, I recommend mounting your Google Drive (see section below), then setting your input and output locations to somewhere inside your drive.\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Ol5uQcZkLvA3",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "image_folder_path = \"\" #@param {type:\"string\"}\n",
        "output_path = \"\" #@param {type:\"string\"}\n",
        "use_sample_data = False #@param {type:\"boolean\"}\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "RsxzdzwtPVCA",
        "colab_type": "text"
      },
      "source": [
        "Download Meshroom and sample data(if needed)."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "cQgXdvk-qUvi",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "if use_sample_data:\n",
        "  !git clone https://github.com/alicevision/dataset_buddha\n",
        "  image_folder_path = './dataset_buddha/buddha'\n",
        "  output_path = './buddha_out'\n",
        "\n",
        "!wget -N https://github.com/alicevision/meshroom/releases/download/v2019.1.0/Meshroom-2019.1.0-linux.tar.gz\n",
        "!mkdir meshroom\n",
        "!tar xzf Meshroom-2019.1.0-linux.tar.gz -C ./meshroom"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "zTI6AlUXd-_M",
        "colab_type": "text"
      },
      "source": [
        "#Google Drive\n",
        "Connect to Google Drive, so that you can import and export files from there.\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "2wodsIcpYbDR",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 122
        },
        "outputId": "82fa9986-d148-4c4b-be58-1ee71e3c2e7b"
      },
      "source": [
        "from google.colab import drive\n",
        "drive.mount('/content/drive')"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3aietf%3awg%3aoauth%3a2.0%3aoob&scope=email%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdocs.test%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive.photos.readonly%20https%3a%2f%2fwww.googleapis.com%2fauth%2fpeopleapi.readonly&response_type=code\n",
            "\n",
            "Enter your authorization code:\n",
            "··········\n",
            "Mounted at /content/drive\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "xA_XKpKqdoqb",
        "colab_type": "text"
      },
      "source": [
        "#Meshing\n",
        "Use the form in setup to specify an input and output path, or check sample data to try it out."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "AZWyk461sxGI",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!mkdir '{output_path}'\n",
        "!./meshroom/Meshroom-2019.1.0/meshroom_photogrammetry --input '{image_folder_path}' --output '{output_path}'\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "7wwo3nPyd0-w",
        "colab_type": "text"
      },
      "source": [
        "#Download\n",
        "Now simply download the output folder from Google Drive!"
      ]
    }
  ]
}